
// 求对象的深度
/* function getDeep(obj){
    var res = 0;
    (function myDeep(obj,num){
        if(typeof obj=== 'object'){
            for(var key in obj){
                if(typeof obj[key] === 'object'){
                    myDeep(obj[key],num+1);
                }else{
                    res = res < num + 1 ? num + 1 : res;
                }
            }
        }
        else{
            res = res > num ? res : num ;
        }
    })(obj,res)
    return res;
} */
/* function getDeep(obj){
    if(typeof(obj)!=='object'){
        return 'no an object'
    }
    let res = 1;
    (function inner(obj,num){
        for(let i in obj){
            if(typeof (obj[i]) === 'object'){
                inner(obj[i], num + 1)
            }else{
                res = res > num ? res : num
            }
        }
    })(obj,res)
    return res
}
let obj1 = {name:1,age:{age1:1}}
let obj = {name:1,age:{age1:1,age2:{a:1}},data:{data1:1,data2:{data2:1,data3:{data:3}}}}
console.log(getDeep(obj)) */
// 方法的复制简单使用浅拷贝就可以，因为和对象不同，方法只有一层

let obj = {
    name:function(){
        console.log('这是 obj中的name方法')
    }
}
let obj2 = {}
for(let key in obj){
    obj2[key] = obj[key]
}
obj2.name = function(){
    console.log('这是复制过来的方法')
}
obj2.name()
obj.name()

// 继承的方式
// 1.原型链继承，将子类的原型链指向父类的原型上面
function Person(name){
    this.name = name
}   
Person.prototype = {
    a:1,
    say:function(){
        console.log(`我叫${this.name},我是person`)
    }
}
function Student(name,goal){
    this.name = name
    this.goal = goal
}
// Student.prototype = new Person() 
Student.prototype.__proto__ = Person.prototype
let s = new Student('李华',100)
s.say()
console.log(Student.prototype)
console.dir(Person.prototype)

// 2.借用构造函数实现继承
/* function Person(name){
    this.name = name
}   
function Student(name,goal){
    Person.call(this,name)
    this.goal = goal
}
let s = new Student('李华',100)
console.log(s) */
// 3.组合式继承

function Person(name){
    this.name = name
}   
Person.prototype = {
    a:1,
    say:function(){
        console.log(`我叫${this.name},我是person`)
    }
}
function Student(name,goal){
    Person.call(this,name)
    this.goal = goal
}
// Student.prototype = new Person() 这样也可以
Student.prototype.__proto__ = Person.prototype
let s = new Student('李华',100)
s.say()
console.log(s)
// 结合了上面共同的优点
